<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
  <style>
    /*2.第二种方式是利用元素的margin/padding百分比是相对父元素width的性质来实现*/
    .square {
      width: 20%;
      height: 0;
      padding-top: 20%;
      background: orange;
    }
  </style>
</head>

<body>
  <div class="square"></div>
</body>

</html>